//
//  BYBaseTableViewController.m
//  School+
//
//  Created by Sean Sebastian on 2/25/16.
//  Copyright © 2016 Sean Sebastian. All rights reserved.
//

#import "BYBaseTableViewController.h"
#import "BYVisitorView.h"

#import "BYHomeTableViewController.h"
#import "BYChatTableViewController.h"
#import "BYDiscoverViewController.h"
#import "BYProfileTableViewController.h"


#import "BYLoginControllerViewController.h"
#import "BYRegisterViewController.h"


#import "UserAccount.h"

@interface BYBaseTableViewController () <VistorViewDelegate>

@end

@implementation BYBaseTableViewController 

- (void)viewDidLoad {
    [super viewDidLoad];

}

// 当实现了这个方法，并且给view设置值，就不会再从其他地方加载view，xib、storyboard
- (void)loadView
{
    self.userLogin = [UserAccount sharedUserAccount].isSignIn;

    if (self.userLogin) {
        [super loadView];
    }else{
        [self setupVisitorView];

    }
}

- (void)setupVisitorView
{
    BYVisitorView *visitorView = [[BYVisitorView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    self.view = visitorView;
    
    // 判断时哪个控制器
    if ([self isKindOfClass:[BYHomeTableViewController class]]) {
        [visitorView startRotationAnimation];
        
    }
    
    
    else if ([self isKindOfClass:[BYProfileTableViewController class]]) {
        
        [visitorView setupInfo:@"visitordiscover_image_profile" andMessage:@"登录后，你的微博、相册、个人资料会显示在这里，展示给别人"];
        
    }
    
    visitorView.vistorViewDelegate = self;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
}

//- (void)didEnterBackground
//{
//    if ([self.view isKindOfClass:[BYVisitorView class]]) {
//        [[[BYVisitorView alloc]init] resumeAnimation];
//    }
//}
//
//- (void)didBecomeActive
//{
//    if ([self.view isKindOfClass:[BYVisitorView class]]) {
//        [[[BYVisitorView alloc] init] pauseAnimation];
//    }
//}


// implement delegate method
- (void)vistorViewLoginClick
{
    // 跳转到登录页面
    // 创建控制器
    BYLoginControllerViewController *vc = [[BYLoginControllerViewController alloc] init];
    // 创建导航控制器
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    vc.title = @"登陆";
    [self presentViewController:nav animated:YES completion:nil];

}

- (void)vistorViewRegistClick
{
    // 跳转到注册页面
    // 创建控制器
    BYRegisterViewController *vc = [[BYRegisterViewController alloc] init];
    // 创建导航控制器
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    vc.title = @"注册";
    [self presentViewController:nav animated:YES completion:nil];
}

@end
